;; The first four lines of this file were added by Dracula.
;; They tell DrScheme that this is a Dracula Modular ACL2 program.
;; Leave these lines unchanged so that DrScheme can properly load this file.
#reader(planet "reader.rkt" ("cce" "dracula.plt") "modular" "lang")
(require "Ivolume.lisp")
(require "M-avl-string-keys.lisp")
(require "Mstock-retrieval.lisp")

(module Mvolume
  (import Itree)
  (import Istockretrieval)
  (include-book "io-utilities" :dir :teachpacks)
  
  (defun volume (ticker data total)
    (if (consp data)
        (let* ((ticktemp (caar data))
               (numtraded (cadr (cddddr (car data)))))
          (if (equal ticktemp ticker)
              (volume ticker (cdr data) (+ total numtraded))
              (volume ticker (cdr data) total)))
        (if (equal total 0)
            (concatenate 'string ticker ": 0 ")
            (concatenate 'string ticker ": " 
                         (int->str total) " "))))
  
  (defun volume-query-with-tickers (tickers data)
    (if (consp tickers)
        (string-append (volume (car tickers) data 0) 
                       (volume-query-with-tickers (cdr tickers) 
                                                  data))
        ""))
  
  (defun volume-query (start end tickers tree)
  (if (consp tickers)
      (volume-query-with-tickers tickers 
                                 (get-stocks-in-range-by-tickers 
                                  tree start 
                                  end tickers))
      (volume-query-with-tickers (get-all-tickers (get-stocks-in-range tree start end)) 
                                 (get-stocks-in-range tree start end))))
  
  (export Ivolume))